package com.zhanggm.springcloud.jpa.entity;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Data;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.springframework.data.annotation.CreatedBy;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedBy;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
import org.springframework.format.annotation.DateTimeFormat;

import javax.persistence.*;
import java.util.Date;
import java.util.List;

@Data
@Entity
@DynamicUpdate
@DynamicInsert
@EntityListeners(AuditingEntityListener.class)
@Table(name="t_user",catalog = "1707d",schema = "1707d")
public class UserEntity {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
    @Column(name = "username",length = 255)
    private String username;
    private String password;
    @Column(name = "phone")
    private String phone;

    @CreatedDate
    @Column(name = "created",columnDefinition = "date")
    @Temporal(TemporalType.TIMESTAMP)
    private Date created;

    @LastModifiedDate
    @Temporal(TemporalType.TIMESTAMP)
    private Date updated;

    @Transient
    private String extend;
    @Transient
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date startDate;
    @Transient
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date endDate;

    //创建人
    @CreatedBy
    private String createdBy;
    //修改人
    @LastModifiedBy
    private String updatedBy;

   /* @JsonIgnoreProperties("user")
    @OneToMany(mappedBy = "user_id",cascade = {CascadeType.MERGE,CascadeType.REFRESH})
    private List<OrderEntity> orderList;*/

    //@JoinTable中属性name ：多对多中间表名称
    //joinColumns ：这个字段是中间表的字段，对应的是主表t_user表中的主键（id）
    //inverseJoinColumns ：这个字段是中间表role_id的字段，对应的是从表t_role表中的主键（id）

    /*@JsonIgnoreProperties("userList")
    @ManyToMany
    @JoinTable(name = "t_user_role_relation",
            joinColumns = @JoinColumn(name = "user_id"),
    inverseJoinColumns = @JoinColumn(name = "role_id"))
    private List<RoleEntity> roleList;*/
}
